<div class="layui-fluid">
  <div class="layui-row">
    <div class="layui-col-xs12">
      <div class="layui-card">
        <div class="layui-card-header">
        	<h2>
          <a href="#/layui/managerList" title="返回上一页">
            <i class="layui-icon">&#xe65c;</i>
          </a>
          <span>编辑用户</span>
          </h2>
        </div>
        <div class="layui-card-body">
          <form class="layui-form" action="" lay-filter="the_form">
            <div class="layui-form-item">
              <label class="layui-form-label">帐号<span class="red">*</span></label>
              <div class="layui-input-block">
                <input type="text" name="LoginId" required lay-verify="required" class="layui-input loginId">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">密码<span class="red">*</span></label>
              <div class="layui-input-block">
                <input type="text" name="Pwd" required lay-verify="required" autocomplete="off" class="pwd layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">同户名<span class="red">*</span></label>
              <div class="layui-input-block">
                <input type="text" name="RealName" required lay-verify="required" autocomplete="off" class="realName layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">性别<span class="red">*</span></label>
              <div class="layui-input-block">
                <select name="Sex" class="page_type sex" lay-filter="pageType" lay-verify="required">
                  <option value="0">女</option>
                  <option value="1">男</option>
                </select>
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">年龄</label>
              <div class="layui-input-block">
                <input type="text" name="Age" autocomplete="off" class="age layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">工号<span class="red">*</span></label>
              <div class="layui-input-block">
                <input type="text" name="WorkNumber" required lay-verify="required|number" autocomplete="off" class="workNumber layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">邮箱</label>
              <div class="layui-input-block">
                <input type="text" name="Email" required autocomplete="off" class="email layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">手机</label>
              <div class="layui-input-block">
                <input type="text" name="Telephone" required autocomplete="off" class="telephone layui-input">
              </div>
            </div>
            <div class="layui-form-item">
              <label class="layui-form-label">是否冻结<span class="red">*</span></label>
              <div class="layui-input-block">
                <select name="IsForbid" class="page_type isForbid" lay-filter="pageType" lay-verify="required">
                  <option value="0">否</option>
                  <option value="1">是</option>
                </select>
              </div>
            </div>
            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo_hash">立即提交</button>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>

<script>
  layui.use(['form','route'], function () {

    var form = layui.form;
    var route = layui.route
    var params = route.params()
    var obj = {}
    form.render();
    if(params !=null) {
      DBHelper.Get('Admin_Xn_User/'+params.userId,function (res) {
        obj = res
        console.log(res)
        // $('.loginId').val(res.LoginId)
        // $('.pwd').val(res.Pwd)
        // $('.realName').val(res.RealName)
        // $('.age').val(res.Age)

        form.val('the_form',{
          LoginId:res.LoginId,
          Pwd:res.Pwd,
          RealName:res.RealName,
          Sex:res.Sex,
          Age:res.Age,
          WorkNumber:res.WorkNumber,
          Email:res.Email,
          Telephone:res.Telephone,
          IsForbid:res.IsForbid,
        })
      },function (res) {
          
      })
    }

    //监听提交
    form.on('submit(formDemo_hash)', function (data) {
      // layer.msg(JSON.stringify(data.field));
      
      if(params !=null) {
        obj.LoginId=data.field.LoginId,
        obj.Pwd=data.field.Pwd,
        obj.RealName=data.field.RealName,
        obj.Sex=data.field.Sex,
        obj.Age=data.field.Age,
        obj.WorkNumber=data.field.WorkNumber,
        obj.Email=data.field.Email,
        obj.Telephone=data.field.Telephone,
        obj.IsForbid=data.field.IsForbid,
        obj.ModifyTime=getNowFormatDate(),
        obj.ModifyUser=localStorage.getItem('user'),
        DBHelper.Put('Admin_Xn_User/'+params.userId,obj,function (res) {
          layer.open({
              content: '修改成功',
              yes: function(index, layero){
                  location.href='#/layui/managerList'
                  layer.close(index);
              }
            })
        },function (res) {
          // body...
        })
      }else {
        var newData = {
          LoginId:data.field.LoginId,
          Pwd:data.field.Pwd,
          RealName:data.field.RealName,
          Sex:data.field.Sex,
          Age:data.field.Age,
          WorkNumber:data.field.WorkNumber,
          Email:data.field.Email,
          Telephone:data.field.Telephone,
          IsForbid:data.field.IsForbid,
          CreateTime:getNowFormatDate(),
          CreateUser:localStorage.getItem('user'),
          ModifyTime:getNowFormatDate(),
          ModifyUser:localStorage.getItem('user'),
          IsDeleted:0,
        }
        DBHelper.Post('Admin_Xn_User',newData,function (res) {
          if(res.Guid){
            layer.open({
              content: '新建成功',
              yes: function(index, layero){
                  location.href='#/layui/managerList'
                  layer.close(index);
              }
            })
          }
        },function (res) {
          // body...
        })
      }


      return false;
    });

  });
</script>
<style>
</style>